import { api } from './baseRequest';

// 微信标签相关API
export const wechatTagApi = {
  // 获取标签列表
  getTagList: async () => {
    try {
      return await api.get('/wechat/tag');
    } catch (error) {
      console.error('获取标签列表失败:', error);
      // 返回模拟数据作为降级方案
      return [];
    }
  },

  // 创建标签
  createTag: async (name) => {
    return await api.post('/wechat/tag', null, {
      params: { name }
    });
  },

  // 更新标签
  updateTag: async (tagId, name) => {
    // 将参数从请求体改为查询参数
    return await api.put('/wechat/tag', null, {
      params: { tagId, name }
    });
  },

  // 删除标签
  deleteTag: async (tagId) => {
    return await api.delete(`/wechat/tag?tagId=${tagId}`);
  },

  // 获取标签粉丝
  getSubscribersByTagId: async (tagId) => {
    return await api.get(`/wechat/tag/subscribers?tagId=${tagId}`);
  },

  // 获取用户标签
  getUserTags: async (openId) => {
    return await api.get(`/wechat/tag/user?openId=${openId}`);
  },

  // 批量打标签
  batchTagUsers: async (openIds, tagId) => {
    return await api.post(`/wechat/tag/batch/tag?tagId=${tagId}`, openIds);
  },

  // 批量取消标签
  batchUntagUsers: async (openIds, tagId) => {
    return await api.post(`/wechat/tag/batch/untag?tagId=${tagId}`, openIds);
  },

  // 同步标签
  syncTagsFromWechat: async () => {
    return await api.post('/wechat/tag/sync');
  }
};

export default wechatTagApi;